@extends('layouts.console_main')

@section('resources')
    @parent
    <style type="text/css">
        #container{ width:670px; height: 400px;}
        .getlngandlat{width:100px; height: 30px;border-radius: 5px;margin-top:4px; background-color: #57d448;}
    </style>
@endsection
@section('content')
    <div class="right_col" role="main">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        @if(isset($id))
                            <h2>水表管理   >>  水表编辑</h2>
                        @else
                            <h2>水表管理   >>  水表新增</h2>
                        @endif

                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                <ul class="dropdown-menu" role="menu">
                                    <li><a href="#">Settings 1</a>
                                    </li>
                                    <li><a href="#">Settings 2</a>
                                    </li>
                                </ul>
                            </li>
                            <li><a class="close-link"><i class="fa fa-close"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <br />
                        <form id="add_watermeter" data-parsley-validate class="form-horizontal form-label-left">
                            <div class="form-group">
                                <label for="middle-name" class="control-label col-md-1 col-sm-3 col-xs-12">地图</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    {{--<div id="container"></div>--}}
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <br />
    </div>
@endsection

@section('scriptResources')
    @parent
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.3&key=a9fe1b184bacd00ecd70365903024419&plugin=AMap.Autocomplete"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <script>
        var lntlatXY;
        var marker, map = new AMap.Map("container", {
            resizeEnable: true,
            zoom: 13
        })
        mapObj = new AMap.Map('iCenter');
        mapObj.plugin('AMap.Geolocation', function () {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                timeout: 10000,          //超过10秒后停止定位，默认：无穷大
                maximumAge: 0,           //定位结果缓存0毫秒，默认：0
                convert: true,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                showButton: true,        //显示定位按钮，默认：true
                buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角
                buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                showMarker: true,        //定位成功后在定位到的位置显示点标记，默认：true
                showCircle: true,        //定位成功后用圆圈表示定位精度范围，默认：true
                panToLocation: true,     //定位成功后将定位到的位置作为地图中心点，默认：true
                zoomToAccuracy:true      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            });
            mapObj.addControl(geolocation);
            geolocation.getCurrentPosition(function(status,result){
                //console.log(status);
                var position = result.position;
                //console.log(result.accuracy);
                //console.log(result.addressComponent);
                var address = result.formattedAddress;
                //console.log(position);
                //console.log(address);
                $.ajax({
                    url : 'http://leichu.wang:9250/position/add',
                    data:{address:address,position:JSON.stringify(position)},
                    dataType:'json',
                    success:function(data){

                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        
                    }
                });
            });
            AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
            AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
        });
    </script>
@endsection
